package com.hc.server.actions;

import java.io.IOException;

import org.json.JSONException;
import org.json.JSONObject;

import com.hc.server.Error;
import com.hc.server.IAction;
import com.hc.server.Request;
import com.hc.server.Response;
import com.hc.server.conn.mall.MallResponse;
import com.hc.server.conn.mall.MallServerHelper;

public class QUERY_AIRLINE implements IAction{

	private final static String SN = "SN";
	private final static String CHECKIN_DATE = "CHECKIN_DATE";
	
	private final static String FROM_CITY = "FROM_CITY";
	private final static String TO_CITY = "TO_CITY";
	private final static String STIME = "STIME";
	private final static String ETIME = "ETIME";
	private final static String CD = "CD";	//航班号
	private final static String COM = "COM"; //航空公司
	private final static String MODEL = "MODEL";//机型
	private final static String MPRICE = "MPRICE";
	private final static String SPRICE = "SPRICE";
	private final static String DISCOUNT = "DISCOUNT";//折扣
	private final static String SEAT = "SEAT";//舱位
	private final static String SAIRPORT = "SAIRPORT";
	private final static String EAIRPORT = "EAIRPORT";
	private final static String TGQ = "TGQ";//退改签的说明
	private final static String STOCK = "STOCK";//库存
	
	private final static String MALL_FROM_CITY = "";
	private final static String MALL_TO_CITY = "";
	private final static String MALL_STIME = "";
	private final static String MALL_ETIME = "";
	private final static String MALL_CD = "";	//航班号
	private final static String MALL_COM = ""; //航空公司
	private final static String MALL_MODEL = "";//机型
	private final static String MALL_MPRICE = "";
	private final static String MALL_SPRICE = "";
	private final static String MALL_DISCOUNT = "";//折扣
	private final static String MALL_SEAT = "";//舱位
	private final static String MALL_SAIRPORT = "";
	private final static String MALL_EAIRPORT = "";
	private final static String MALL_TGQ = "";//退改签的说明
	private final static String MALL_STOCK = "";//库存
	
	@Override
	public void execute(Request req, Response resp) {
		// 1.处理参数
		String pdtSn;
		String checkInDate;
		try {
			pdtSn = req.getStrArg(SN);
			checkInDate = req.getStrArg(CHECKIN_DATE);
		} catch (Exception e) {
			resp.setErrResp(Error.INVALID_ARGS_ERR_CD,
					Error.INVALID_ARGS_ERR_MSG);
			return;
		}
		// 2.查询
		MallResponse mResp = null;
		try {
			mResp = MallServerHelper.queryAirline(pdtSn, checkInDate);
		} catch (JSONException e) {
			e.printStackTrace();
			resp.setErrResp(Error.MALLSERVER_DATA_FORMAT_ERR_CD, Error.MALLSERVER_DATA_FORMAT_ERR_MSG);
			return;
		} catch (IOException e) {
			e.printStackTrace();
			resp.setErrResp(Error.MALLSERVER_NET_ERR_CD, Error.MALLSERVER_NET_ERR_MSG);
			return;
		}
		if (0 != mResp.getRetCode()) {
			resp.setErrResp(Error.MALLSERVER_ERR_CD, mResp.getErrorMsg());
			return;
		}
		try {
			JSONObject mAirline = mResp.getResult();			
			resp.appendRespContent(CD, mAirline.getString(MALL_CD));
//			resp.appendRespContent(COM, value);
			resp.appendRespContent(FROM_CITY, mAirline.get(MALL_FROM_CITY));
//			resp.appendRespContent(TO_CITY, value);
//			resp.appendRespContent(CHECKIN_DATE, value);
//			resp.appendRespContent(STIME, value);
//			resp.appendRespContent(ETIME, value);
//			resp.appendRespContent(SAIRPORT, value);
//			resp.appendRespContent(EAIRPORT, value);
//			resp.appendRespContent(MODEL, value);
//			resp.appendRespContent(MPRICE, value);
//			resp.appendRespContent(SPRICE, value);
//			resp.appendRespContent(DISCOUNT, value);
//			resp.appendRespContent(SEAT, value);
//			resp.appendRespContent(STOCK, value);
//			resp.appendRespContent(TGQ, value);
		}catch (JSONException e) {
			e.printStackTrace();
			resp.setErrResp(Error.SERVER_SYS_ERR_CD, Error.SERVER_SYS_ERR_MSG);
			return;
		}
		return;
	}

}
